package com.servicesystem.servicesystem.controller.douyin;

import com.alibaba.fastjson.JSON;
import com.servicesystem.servicesystem.service.SubscriptionService;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


/**
 * @author X
 * @version 1.0
 * @ClassName SubscriptionController
 * @description
 * @date 2020/9/8
 **/
@Log4j2
@Controller
@RequestMapping("/news")
public class SubscriptionController {

    @Autowired
    private SubscriptionService subscriptionService;

    /***
     * 订单消息订阅
     * @return
     */
    @PostMapping(value = "/orderSubscription", consumes = "application/json; charset=utf-8")
    public void orderSubscription(@RequestBody List<Map<String, Object>> subscriptionInfo,
                                  HttpServletResponse response) {
        HashMap<String, Object> hashMap = new HashMap<>();
        hashMap.put("code", 0);
        hashMap.put("msg", "success");
        String result = JSON.toJSONString(hashMap);

        log.info("抖店返回的数据" + subscriptionInfo);
        try {
            PrintWriter out = response.getWriter();
            out.print(result);
            out.close();
        } catch (Exception e) {
            System.out.println(e);
        }
        subscriptionService.orderSubscription(subscriptionInfo);
    }
}

